package com.hung.triple.loadbalancer;

import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author Hung
 * @date 2022/9/24 23:21
 */
public class RandomLoadBalancer<T> implements AbstractLoadBalancer<T> {

    @Override
    public T select(List<T> instances) {
        return instances.get(ThreadLocalRandom.current().nextInt(instances.size()));
    }

    public static String selectOne(List<String> instances) {
        return instances.get(ThreadLocalRandom.current().nextInt(instances.size()));
    }

}